package org.breathe.dynamic.thread.pool.starter.cloud.nacos.autoconfiguration;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.cloud.nacos.NacosConfigProperties;
import org.breathe.dynamic.thread.pool.starter.cloud.nacos.refresh.CloudNacosRefresher;
import org.breathe.dynamic.thread.pool.starter.common.autoconfigure.BaseBeanAutoConfiguration;
import org.breathe.thread.pool.common.constant.BreatheDtpConstant;
import org.breathe.thread.pool.common.entity.BreatheDtpProperties;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置的自动注入
 * @author: breathe
 * @createTime: 2025-04-13
 */
@Configuration
@EnableConfigurationProperties(BreatheDtpProperties.class)
@ConditionalOnClass(NacosConfigProperties.class)
@ConditionalOnProperty(value = BreatheDtpConstant.DTP_ENABLED_PROP, matchIfMissing = true, havingValue = "true")
@ImportAutoConfiguration({BaseBeanAutoConfiguration.class})
public class BreatheDtpAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnClass(NacosConfigManager.class)
    public CloudNacosRefresher cloudNacosRefresher() {
        return new CloudNacosRefresher();
    }
}
